﻿using AntdUI;
using LiveChartsCore.Drawing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TCOChart
{
    public partial class MessageTipsForm : Form
    {
        public MessageTipsForm()
        {
            InitializeComponent();
        }

        private void button_drawer_Click(object sender, EventArgs e)
        {
            AntdUI.Drawer.open(new AntdUI.Drawer.Config(this, new Form1() { Size = new Size(300, 300) })
            {
                Align = AntdUI.TAlignMini.Right,
                Mask = true,
                MaskClosable = true,  //true表示不需要手动关闭
                DisplayDelay = 500,  // 延迟弹出
            });
        }

        private void button_global_Click(object sender, EventArgs e)
        {
            AntdUI.Message.success(this, "this is a successful information", autoClose: 3);
        }

        private void button_align_Click(object sender, EventArgs e)
        {
            AntdUI.Message.open(new AntdUI.Message.Config(this, "this is a successful information", AntdUI.TType.Success) { 
                AutoClose = 3,
                Align = AntdUI.TAlignFrom.TR,
            });
        }

        private void button_loading_Click(object sender, EventArgs e)
        {
            button_loading.Loading = true;
            AntdUI.Message.loading(this, "loading........", call: (config) =>
            {
                config.Padding = new Size(10, 5);
                // 执行延时操作
                Thread.Sleep(1000);
                config.Text = "全力加载中...";
                config.Refresh();
                Thread.Sleep(1000);
                config.Error("加载失败..");
                button_loading.Loading = false;
            }, autoClose:2);
        }

        private void button_modal_Click(object sender, EventArgs e)
        {
            AntdUI.Modal.open(new AntdUI.Modal.Config(this, "Modal Title", "this is an introduction of the main content,\n respectively... ")
            {
                Icon = AntdUI.TType.Success,
                Padding = new Size(10, 5), 
                Draggable = true,  // 支持拖拽  // 默认
                BtnHeight = 38,  // 按钮高度，默认为38，当为0时，按钮不存在
                CancelText = "Cancel",  // 设置取消按钮文本  当设置为null时，按钮不存在
                OkText = "OK",  // 设置确认按钮文本
            });
        }

        private void button_modalCustom_Click(object sender, EventArgs e)
        {
            AntdUI.Modal.open(new AntdUI.Modal.Config(this, "Modal Title", "This is a custom button mode box, respectively...")
            {
                // 自定义按钮
                Btns = new Modal.Btn[]
                {
                    new Modal.Btn("submit", "submit", TTypeMini.Success),
                    new Modal.Btn("return", "return", TTypeMini.Warn),
                },
                CancelText = null,
                OkText = "OK",
                OnOk = config =>
                {
                    Thread.Sleep(1000);
                    AntdUI.Message.info(this, config.OkText, autoClose: 2);
                    return true;
                },
                OnBtns = config =>{
                    Thread.Sleep(1000);
                    AntdUI.Message.info(this, config.Text, autoClose: 2);
                    switch (config.Text)
                    {
                        case "return":
                            return false;
                        case "submit":
                            return true;
                        default:
                            return true;
                    }
                }
            });
        }

        private void button_mask_Click(object sender, EventArgs e)
        {
            AntdUI.Modal.open(new AntdUI.Modal.Config(this, "Modal Mask Title", "this is a modal frame with no shadow")
            {
                Mask = false,
                MaskClosable = false,  // 点击外侧是否能关闭
                Keyboard = false,      // 能否通过键盘点击关闭
                CloseIcon = true,      // 是否显示关闭图标  默认false
            });
        }

        private void button_customForm_Click(object sender, EventArgs e)
        {
            using (var form = new FormPort())
            {
                AntdUI.Modal.open(new AntdUI.Modal.Config(this, "系统设置", form, TType.Info)
                {
                    CloseIcon = true,
                });
            }
        }

        private void button_notification_Click(object sender, EventArgs e)
        {
            AntdUI.Notification.info(this, "title", "This is a normal notification prompt box", autoClose: 3, align:TAlignFrom.TR);
        }

        private void button_notificationClose_Click(object sender, EventArgs e)
        {
            AntdUI.Notification.open(new AntdUI.Notification.Config(this, "title", "this is a reminder box that can be set with or without a close button ", TType.Info, TAlignFrom.BL)
            {
                ClickClose = false, // 点击通知是否关闭
                CloseIcon = false, // 关闭图标

                // 超链接
                Link = new Notification.ConfigLink("link to...", () =>
                {
                    using (var form = new FormPort())
                    {
                        AntdUI.Modal.open(new AntdUI.Modal.Config(this, "系统设置", form, TType.Info)
                        {
                            CloseIcon = true,
                        });
                    }
                    return true;
                }),
            });
        }

        private void button_spin_Click(object sender, EventArgs e)
        {
            AntdUI.Spin.open(panel1, new AntdUI.Spin.Config()
            {
                Back = Color.FromArgb(220, 147, 181, 207),
                Color = Style.Db.Primary,//转圈颜色
                Radius = 6,
                Fore = Color.Black,//字体颜色
                Font = new Font("Microsoft YaHei UI", 14f),//字体可以控制进度圈的大小
            }, (config) =>
            {
                for (int i = 0; i < 100; i++)
                {
                    config.Text = $"加载进度{i}%";
                    config.Value = i*0.01f;
                    Thread.Sleep(100);
                }
                config.Text = "加载完成";
                Thread.Sleep(1000);
            }, () =>
            {
                // 结束执行....
            });
        }
    }
}
